package com.baizhi.action;

import com.baizhi.entity.Brand;
import com.baizhi.entity.Phone;
import com.baizhi.service.PhoneService;
import com.baizhi.service.impl.PhoneSerciceImpl;

import java.util.ArrayList;
import java.util.List;

public class PhoneActon {
    private Phone phone;
    private Integer id;

    private Integer page;
    private Integer rows;
    private Integer sum;
    private Integer sum1;
    private List<Integer> phoneId = new ArrayList<>();
    private List<Phone> phones;
    private PhoneService service=new PhoneSerciceImpl();

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public List<Integer> getPhoneId() {
        return phoneId;
    }

    public void setPhoneId(List<Integer> phoneId) {
        this.phoneId = phoneId;
    }

    public Integer getSum1() {
        return sum1;
    }

    public void setSum1(Integer sum1) {
        this.sum1 = sum1;
    }

    public Integer getSum() {
        return sum;
    }

    public void setSum(Integer sum) {
        this.sum = sum;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getRows() {
        return rows;
    }

    public void setRows(Integer rows) {
        this.rows = rows;
    }

    public PhoneService getService() {
        return service;
    }

    public void setService(PhoneService service) {
        this.service = service;
    }

    public List<Phone> getPhones() {
        return phones;
    }

    public void setPhones(List<Phone> phones) {
        this.phones = phones;
    }

    public Phone getPhone() {
        return phone;
    }

    public void setPhone(Phone phone) {
        this.phone = phone;
    }

    ///////////////////////////////
    //分页查询
    public String selectPhone() {
        if(page==null){
            page=1;
        }
        if(rows==null){
            rows=3;
        }
        // 这是分页查询
        phones = service.selectPhone(page, rows);
//            查询页数
        sum1 = service.selectPhoneSum();
        sum=sum1%rows==0 ?sum1/rows:sum1/rows+1;
        return "selectPhone";

    }

    //添加手机
    public String insertPhone() {
        service.insertPhone(phone);
        System.out.println("添加手机: "+phone);
        return "insertPhone";
    }

    //删除手机
    public String deletePhone() {
        for (Integer i:phoneId) {
            System.out.println("删除ID为:"+i);
            service.deletePhone(i);
        }
        return "deletePhone";
    }

    //查询一条数据
    public String selectPhoneOne() {
        phone = service.selectPhoneOne(id);
        System.out.println("查询一条数据:"+id);
        System.out.println("查询一条数据:"+phone);
        return "selectPhoneOne";
    }

    //修改条数据
    public String updatePhone() {
        System.out.println("修改条数据:"+phone);
        service.updatePhone(phone);
        return "updatePhone";
    }

//
//    public List<Brand> selectBrand();
//
//    public void insertBrand(Brand brand);
//
//    public void deleteSomePhone(Integer id);
//
//    public void deleteBrand(Integer id);


    private List<Brand> brands=new ArrayList();
    private Brand brand;
    private Integer brandId;

    public List<Brand> getBrands() {
        return brands;
    }

    public void setBrands(List<Brand> brands) {
        this.brands = brands;
    }

    public Brand getBrand() {
        return brand;
    }

    public void setBrand(Brand brand) {
        this.brand = brand;
    }

    public Integer getBrandId() {
        return brandId;
    }

    public void setBrandId(Integer brandId) {
        this.brandId = brandId;
    }


//查询全部   brand
    public String selectBrand() {
        System.out.println("查询全部brand:"+brands);
        brands = service.selectBrand();
        return "selectBrand";
    }

//添加   brand
    public String insertBrand() {
        System.out.println("添加brand:"+brand);
         service.insertBrand(brand);
        return "insertBrand";
    }

//删除  brand
    public String deleteSomePhone() {
        System.out.println("删除brand:"+brandId);
        service.deleteSomePhone(brandId);
        service.deleteBrand(brandId);
        return "deleteSomePhone";
    }



//zzz
    //z2
////111111


}
